//
//  MasViewController.m
//  GYStudyOC
//
//  Created by czera on 2020/11/8.
//  Copyright © 2020 czera. All rights reserved.
//

#import "MasViewController.h"
#import "GYMapTopView.h"
#import "GYMapTopView1.h"

@interface MasViewController ()
@property (nonatomic,assign) BOOL isSwitch;
@property (nonatomic,strong) UIButton *switchBtn;
@property (nonatomic,strong) UIView *centBgView;
@property (nonatomic,strong)UIView *bgView;

@property(nonatomic,strong)GYMapTopView *topView;
@property(nonatomic,strong)GYMapTopView1 *topView1;

@end

@implementation MasViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor lightGrayColor];
    
//    // 视图写在 控制器view上
//    [self loacSet];
//
//    // 视图写在自定义View上
//    _topView = [[GYMapTopView alloc] init];
//    [self.view addSubview:_topView];
//    [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left).offset(40);
//        if (self.bgView == nil) {
//            make.top.equalTo(self.view.mas_top).offset(120);
//        }else {
//            make.top.equalTo(self.bgView.mas_bottom).offset(20);
//        }
//        make.right.equalTo(self.view.mas_right).offset(-40);
//    }];
//    [self.view layoutIfNeeded];
//
//    _topView.layer.borderColor = [UIColor redColor].CGColor;
//    _topView.layer.borderWidth = 2;

    
    _topView1 = [[GYMapTopView1 alloc] init];
    [self.view addSubview:_topView1];
    _topView1.backgroundColor = [UIColor greenColor];
    [_topView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(40);
        make.top.equalTo(self.view.mas_top).offset(400);
        make.right.equalTo(self.view.mas_right).offset(-40);
    }];
    _topView1.layer.borderColor = [UIColor redColor].CGColor;
    _topView1.layer.borderWidth = 2;

    [self.view layoutIfNeeded];

    NSLog(@"====>_topView1 frame %f  %f",_topView1.frame.size.width,_topView1.frame.size.height);
    
    
}

-(void)loacSet{
    _bgView = [[UIView alloc] init];
    [self.view addSubview:_bgView];
    _bgView.backgroundColor = [UIColor greenColor];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(40);
        make.top.equalTo(self.view.mas_top).offset(100);
        make.right.equalTo(self.view.mas_right).offset(-40);
    }];
    _bgView.layer.borderColor = [UIColor redColor].CGColor;
    _bgView.layer.borderWidth = 2;
    
    
    UILabel *titleLab = [[UILabel alloc] init];
    [_bgView addSubview:titleLab];
    titleLab.backgroundColor = [UIColor yellowColor];

    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bgView.mas_left).offset(10);
        make.top.equalTo(_bgView.mas_top).offset(10);
        make.right.equalTo(_bgView.mas_right).offset(-10);
    }];

    _centBgView = [[UIView alloc] init];
    _centBgView.backgroundColor = [UIColor redColor];
    [_bgView addSubview:_centBgView];
    [_centBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_left);
        make.right.equalTo(titleLab.mas_right).offset(-100);
        make.top.equalTo(titleLab.mas_bottom).offset(10);
        make.height.mas_equalTo(40);
    }];

    _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_bgView addSubview:_switchBtn];
    [_switchBtn addTarget:self action:@selector(switchBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    _switchBtn.backgroundColor = [UIColor blackColor];
    [_switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_centBgView.mas_top);
        make.right.equalTo(_bgView.mas_right);
        make.height.width.mas_equalTo(32);
    }];

    _switchBtn.layer.borderColor = [UIColor redColor].CGColor;
    _switchBtn.layer.borderWidth = 1;

    UILabel *titleLab1 = [[UILabel alloc] init];
    [_centBgView addSubview:titleLab1];
    titleLab1.backgroundColor = [UIColor yellowColor];
    titleLab1.numberOfLines = 0;
    titleLab1.text = @"kkjsde";
    [titleLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_centBgView.mas_left).offset(10);
        make.top.equalTo(_centBgView.mas_top).offset(10);
        make.right.equalTo(_centBgView.mas_right).offset(-100);
    }];

    UIView *bottomView = [[UIView alloc] init];
    [_bgView addSubview:bottomView];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_left);
        make.right.equalTo(titleLab.mas_right);
        make.top.equalTo(_centBgView.mas_bottom).offset(10);
        make.bottom.equalTo(_bgView.mas_bottom).offset(-10);
        make.height.mas_equalTo(20);
    }];
    [self.view layoutIfNeeded];


    titleLab.numberOfLines = 0;
    titleLab.text = @"课阿斯蒂芬就物品几节课";

//    return;
    /**********label上文字两端对齐***********/
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:titleLab.text];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    //设置label每行文字之间的行间距
//    paragraphStyle1.lineSpacing=8;
    //设置文字两端对齐
    paragraphStyle1.alignment=NSTextAlignmentJustified;
    NSDictionary * dic =@{
                          //这两个一定要加哦。否则就没效果啦
                          NSParagraphStyleAttributeName:paragraphStyle1,
                          NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],
                          };

    [attributedString1 setAttributes:dic range:NSMakeRange(0, attributedString1.length)];
    [titleLab setAttributedText:attributedString1];
    
    
    
//    _bgView = [[UIView alloc] init];
    NSLog(@"===> %f  %f",_bgView.frame.size.width,_bgView.frame.size.height);
}


-(void)switchBtnAction:(id)sender{

    if (!self.isSwitch) {
        [UIView animateWithDuration:0.5 animations:^{

            self.switchBtn.imageView.transform = CGAffineTransformMakeRotation(M_PI);
            [self.centBgView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(100);
            }];
            [self.view layoutIfNeeded];
        }];
        self.isSwitch = YES;
    }
    else
    {
        [UIView animateWithDuration:0.5 animations:^{

            self.switchBtn.imageView.transform = CGAffineTransformIdentity;

            [self.centBgView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(40);
            }];
            [self.view layoutIfNeeded];
        }];
        self.isSwitch = NO;
    }
}



@end
